;!function () {
  var element;
  var form;
  var layer;
  var $;
  layui.use('element', function () {
    element = layui.element;
    form = layui.form;
    layer = layui.layer;
    $ = layui.jquery;
  });

  /*input字符限制*/
  $("input[max], textarea[max]").each(function () {
    var $this =  $(this);
    var inputWrap  = $('<div class="inputwrap" style="position: relative;"></div>')
    $this.wrap(inputWrap);
    var max = $this.attr('max');
    var len = 0;
    if($this.get(0).tagName  == 'TEXTAREA'){
      var $span = $("<span style='bottom: 0; top: auto;' class='maxlen'><span class='currnum'>0</span>/<span class='text-muted'>"+max+"</span></span>");
    } else {
      var $span = $("<span class='maxlen'><span class='currnum'>0</span>/<span class='text-muted'>"+max+"</span></span>");
    }
    $span.insertAfter($this);
    $(document).on('input propertychange',$this, function () {
      $this.parents('.inputwrap').find('.currnum').html($this.val().length);
    });
  });

  /*tips 弹出*/
  var tip_index = 0;
  $("[data-toggle='tips']").on('mouseover', function(){
    var type = $(this).data('type');
    if(type == 'img'){
      var imgurl = $(this).data('url');
      var width = $(this).data('width') || 260;
      var that = this;
      tip_index=layer.tips('<img src='+imgurl+'>', that, {
        time:0,
        skin: 'mytips',
        area: [width+'px', ''],
        tipsMore:true
      });
    } else {
      var title = $(this).data('title');
      var that = this;
      tip_index=layer.tips(title, that, {
        time:0,
        tipsMore:true
      });
    }

  }).on('mouseout', function () {
    layer.close(tip_index);
  });
  /*二级菜单申缩效果*/
  $(".side-right .layui-nav-item>a").on("click", function () {
    // $(this).next(".layui-nav-child").stop().slideToggle();
  })

  /*页面提示关闭*/
  $(".close_alert").on('click', function () {
    $(this).parents('.alert-msg').hide();
  });

  /*一级菜单切换*/
  $(".side-left .layui-nav-item").on('click', function () {
    var id = $(this).data('navid');
    if(id){
      $(".nav-tree_item").hide();
      $("#"+id).show();
    }
  });

  /*关闭弹框*/
  $(document).on('click','[close-popup]', function () {
    layer.closeAll();
  });


/*  $(".table_action_group .more>a").on('click', function (e) {
    e.stopPropagation();
    $('.more_child').hide();
    $(this).next().slideToggle();
  });*/
  //隐藏表格更多菜单
  $(document).on("click" ,function (e) {
    $('.more_child').hide();
  });
  $(window).resize(function () {
    $(".more_child").hide();
  });
  $(".page-body").scroll(function () {
    $(".more_child").hide();
  });

  $(document).on('click', '.side-left_bottom_nav li', function () {
    $(this).siblings().removeClass('active');
    $(this).addClass('active');
  });

  $(".side-right .layui-nav-item" ).each(function(index,el){
    if($(this).find(".layui-nav-child").length > 0) {

      $(this).find("a").eq(0).css("font-weight", "bold");
    }
  });

}();

// 定位当前页面
function currNav(a,b,c){
  // a->一级，b->二级， c->三级

  var level_1 = $('.side-left .layui-nav-item').eq(a-1);
  var vid = level_1.data('navid');
  console.log(vid);
  level_1.addClass('layui-this');
  level_1.trigger('click');
  var level_2 = $('#'+vid).find('.layui-nav-item').eq(b-1)
  if(c == 0 ){
    level_2.addClass('layui-this');
  } else {
    level_2.addClass('layui-nav-itemed');
  }

  level_2.find('.layui-nav-child').show();
  level_2.find('.layui-nav-child > dd').eq(c-1).addClass('layui-this');
}

function more(a){
  event.stopPropagation();
  var next = $(a).next('.more_child');
  var ttop = next.height() +35;
  var l = $(a).offset().left;
  var t = $(a).offset().top + 30;
  console.log($(".page-layout").height());
  if(t>$(".page-body").height()-100){
    next.css({
      left: l,
      top: t - ttop
    });
  } else {
    next.css({
      left: l,
      top: t
    });
  }

  $('.more_child').hide();
  next.stop().slideToggle();
  //  $(this).next().slideToggle();
}

